//
//  DivicesViewController.m
//  Runone
//
//  Created by runone01 on 16/8/3.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "AppDelegate.h"
#import "HighWayRoadRecord.h"
#import "Define.h"
#import "DevicesViewController.h"
#import "CODetailListController.h"
#import "CameraGunDetailListController.h"
#import "VDDetailListController.h"
#import "BoardDetaillListController.h"
#import "CameraGunDetailViewController.h"
#import "SVProgressHUD.h"
#import "DevicesViewCell.h"
#import "RequestHelper.h"
#import "MJExtension.h"
#import "SVProgressHUD.h"
#import "HighwayMergeRoadRecordModel.h"
#import "HighwayMergeInfoModel.h"
#import "MergeJsonModel.h"
#import "DeviceAndTollCell.h"
#import "BoardDetaillListController.h"
#import "CameraGunDetailListController.h"
#import "TollStationViewController.h"
#import "HighwayMergeInfoModel.h"
#import "HighwayMergeRoadRecordModel.h"
#import "DeviceBaseInfo.h"
#import "OneConst.h"

@interface DevicesViewController ()

//@property(nonatomic,strong)DevicesViewCell *DevicesViewCell;


// ****************************** -数据数组- ******************************

@property (nonatomic, strong) NSMutableArray *staionArray;

// ****************************** -数据数组- ******************************
@property (nonatomic, strong) NSArray *leftArray;
@property (nonatomic, strong) NSArray *rightArray;

//@property (nonatomic, strong) HighwayMergeRoadRecordModel *roadModel;

// xxxxxxxxxxxxxxxxxxxxxxxxxxxx -上下切换的模型- xxxxxxxxxxxxxxxxxxxxxxxxxxxx
@property (nonatomic, strong) HighwayMergeRoadRecordModel *currentRoadModel;//当前道路的模型

@end

@implementation DevicesViewController

#pragma    -----------设施主界面


- (void)viewDidLoad {
    [super viewDidLoad];
    AppDelegate *myDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    _currentRoadModel = myDelegate.HighWayRoadArray[0];  //主线道路模型
    
    [self setTitleOnTheRoad];
    
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    self.tableView.backgroundColor=[UIColor whiteColor];
    [self.tableView registerNib:[UINib nibWithNibName:@"DeviceAndTollCell" bundle:nil] forCellReuseIdentifier:@"DeviceCell"];
    self.tableView.bounces                      = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.automaticallyAdjustsScrollViewInsets   = NO;
    self.tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);

}
//设置标题
- (void) setTitleOnTheRoad {
    UILabel *label      = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
    label.text          = _currentRoadModel.RoadName;
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor     = [UIColor whiteColor];
    self.navigationItem.titleView=label;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden            = YES;
    self.navigationController.navigationBar.hidden = NO;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    HighwayMergeInfoModel *model = _currentRoadModel.mergeInfoList[indexPath.row];
    if ( model.mergeType ==0 && indexPath.row == _currentRoadModel.mergeInfoList.count -1 ) {
        return 40;
    }
    return 200;
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _currentRoadModel.mergeInfoList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DeviceAndTollCell *devicesCell      = [tableView dequeueReusableCellWithIdentifier:@"DeviceCell" forIndexPath:indexPath];
    HighwayMergeInfoModel *infoModel    = _currentRoadModel.mergeInfoList[indexPath.row];
    if (indexPath.row == _currentRoadModel.mergeInfoList.count - 1) {
        devicesCell.midView.hidden = YES;
    }else {
        devicesCell.midView.hidden = NO;
    }
    [devicesCell setHighWayRoadModel:_currentRoadModel andMergeInfo:infoModel];
    //cell中按钮点击回调
    __weak typeof(self) weakSelf  = self;
    devicesCell.ClickButton = ^(NSInteger tag, NSArray *array, HighwayMergeRoadRecordModel *model){
        switch (tag) {
            case 0:{
                _currentRoadModel  = model ;
                [self setTitleOnTheRoad];
                [self.tableView reloadData];
                [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
                break;
            }
            case 1:{
//                NSLog(@"收费站或者枢纽");
                TollStationViewController *stationVC = [[TollStationViewController alloc] init];
                stationVC.currentRoadModel           = weakSelf.currentRoadModel;
                stationVC.mergeModel                 = infoModel;
                [weakSelf.navigationController pushViewController:stationVC animated:YES];
                break;
            }
            case 2:
                _currentRoadModel  = model ;
                [self setTitleOnTheRoad];
                [self.tableView reloadData];
                [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
                break;
            case 3:{
//                NSLog(@"左边情报板");
                BoardDetaillListController *vc = [[BoardDetaillListController alloc] init];
                vc.contentArray                = array;
                vc.currentRoadModel            = _currentRoadModel;
                [weakSelf.navigationController pushViewController:vc animated:YES];
                break;
            }
            case 4:{
//                NSLog(@"左边摄像枪");
                CameraGunDetailListController * cameraVC = [[CameraGunDetailListController alloc] init];
                cameraVC.contentArray        = array;
                cameraVC.currentRoadModel    = _currentRoadModel;
                cameraVC.roadType            = RoadTypeUp;//上行
                [weakSelf.navigationController pushViewController:cameraVC animated:YES];
                break;
            }
            case 5: {
//                NSLog(@"右边情报板");
                BoardDetaillListController *vc = [[BoardDetaillListController alloc] init];
                vc.contentArray                = array;
                vc.currentRoadModel            = _currentRoadModel;
                [weakSelf.navigationController pushViewController:vc animated:YES];
            }
                break;
            case 6: {
//                NSLog(@"右边摄像枪");
                CameraGunDetailListController * cameraVC = [[CameraGunDetailListController alloc] init];
                cameraVC.contentArray        = array;
                cameraVC.currentRoadModel    = _currentRoadModel;
                cameraVC.roadType            = RoadTypeDown;
                [weakSelf.navigationController pushViewController:cameraVC animated:YES];
            }
                break;
            default:
                break;
        }
    };
    return devicesCell;
}


@end
